package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.vo.req.FkwzInstitutionReqVO;
import com.ruoyi.system.vo.req.ImportInstitutionReqDTO;
import com.ruoyi.system.vo.resp.FkwzInstitutionRespVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.service.IFkwzInstitutionService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 重点单位Controller
 * 
 * @author ruoyi
 * @date 2024-05-30
 */
@RestController
@RequestMapping("/institution")
public class FkwzInstitutionController extends BaseController
{
    @Autowired
    private IFkwzInstitutionService fkwzInstitutionService;

    /**
     * 查询重点单位列表
     */
    @RequiresPermissions("system:institution:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody FkwzInstitutionReqVO fkwzInstitution)
    {
        startPage();
        List<FkwzInstitutionRespVO> list = fkwzInstitutionService.selectFkwzInstitutionList(fkwzInstitution);
        return getDataTable(list);
    }

    /**
     * 导出重点单位列表
     */
//    @RequiresPermissions("system:institution:export")
    @Log(title = "重点单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FkwzInstitutionReqVO fkwzInstitution)
    {
        List<FkwzInstitutionRespVO> list = fkwzInstitutionService.selectFkwzInstitutionList(fkwzInstitution);
        ExcelUtil<FkwzInstitutionRespVO> util = new ExcelUtil<FkwzInstitutionRespVO>(FkwzInstitutionRespVO.class);
        util.exportExcel(response, list, "重点单位数据");
    }

    /**
     * 获取重点单位详细信息
     */
    @RequiresPermissions("system:institution:getInfo")
    @GetMapping(value = "/{institutionId}")
    public AjaxResult getInfo(@PathVariable("institutionId") Long institutionId)
    {
         FkwzInstitutionRespVO fkwzInstitutionRespVO = fkwzInstitutionService.selectFkwzInstitutionByInstitutionId(institutionId);
        return AjaxResult.success(fkwzInstitutionRespVO);
    }

    /**
     * 新增重点单位
     */
    @RequiresPermissions("system:institution:add")
    @Log(title = "重点单位", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FkwzInstitutionReqVO fkwzInstitution)
    {
        return toAjax(fkwzInstitutionService.insertFkwzInstitution(fkwzInstitution));
    }

    /**
     * 修改重点单位
     */
    @RequiresPermissions("system:institution:edit")
    @Log(title = "重点单位", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody FkwzInstitutionReqVO fkwzInstitution)
    {
        return toAjax(fkwzInstitutionService.updateFkwzInstitution(fkwzInstitution));
    }

    /**
     * 删除重点单位
     */
    @RequiresPermissions("system:institution:remove")
    @Log(title = "重点单位", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{institutionId}")
    public AjaxResult remove(@PathVariable Long institutionId)
    {
        return toAjax(fkwzInstitutionService.deleteFkwzInstitutionByInstitutionId(institutionId));
    }



    @RequiresPermissions("system:institution:import")
    @ApiOperation("导入")
    @PostMapping("/import")
    public TableDataInfo importInstitutionTask(@RequestParam(value = "file") MultipartFile file) throws IOException {
//        startPage();
        List<ImportInstitutionReqDTO> importInstitutionReqDTOS = fkwzInstitutionService.importInstitutionTask(file);
        return  getDataTable(importInstitutionReqDTOS);
    }


    @RequiresPermissions("system:institution:getCheckQuestionnaire")
        @ApiOperation("检查填报")
    @GetMapping("/getCheckQuestionnaire")
    public AjaxResult getCheckQuestionnaire(@RequestParam Integer id) {

        FkwzInstitutionRespVO institutionRespVO = fkwzInstitutionService.getCheckQuestionnaire(id);
        return AjaxResult.success(institutionRespVO);
    }


}
